package com.neu.questionnaire_system.service.impl;

import com.neu.questionnaire_system.beans.ResponseEntity;
import com.neu.questionnaire_system.entity.Admin;
import com.neu.questionnaire_system.mapper.AdminMapper;
import com.neu.questionnaire_system.service.AdminService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.neu.questionnaire_system.util.Constants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author xingle
 * @since 2022-10-31
 */
@Service
public class AdminServiceImpl extends ServiceImpl<AdminMapper, Admin> implements AdminService {

    @Autowired
    private AdminMapper adminMapper;

    /**
     * created by libo 管理员登录业务
     * @param admin 传入的管理员
     * @return 返回统一的对象
     */
    public ResponseEntity loginAdmin(Admin admin){

        ResponseEntity responseEntity = new ResponseEntity();

        Admin admin1 = adminMapper.queryAdminInfo(admin);
        if (admin1!=null){
            responseEntity.setCode(Constants.SUCCESS_CODE);
            responseEntity.setData(admin1);
            responseEntity.setMessage(Constants.LOGIN_SUCCESS_MESSAGE);
        }else {
            responseEntity.setCode(Constants.FAIL_CODE);
            responseEntity.setMessage(Constants.LOGIN_FAIL_MESSAGE);
        }
        return responseEntity;
    }
}
